metadata: add version to format
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 23 Jan 2016 11:54:35 +0000 (14:54 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 25 Jan 2016 14:12:37 +0000 (17:12 +0300)
src/bin/metadata.rs
src/cargo/ops/cargo_output_metadata.rs
tests/test_cargo_metadata.rs

index 599cce242ba82b6f6f40631eaf563a538a00969e..805d2fac147377916460e791fa0534a07279765e 100644 (file)
@@ -11,14 +11,15 @@ use cargo::util::{CliResult, Config};
 
 #[derive(RustcDecodable)]
 struct Options {
+    flag_color: Option<String>,
     flag_features: Vec<String>,
+    flag_format_version: u32,
     flag_manifest_path: Option<String>,
     flag_no_default_features: bool,
     flag_output_format: String,
     flag_output_path: Option<String>,
-    flag_verbose: bool,
     flag_quiet: bool,
-    flag_color: Option<String>,
+    flag_verbose: bool,
 }
 
 pub const USAGE: &'static str = "
@@ -29,16 +30,18 @@ Usage:
     cargo metadata [options]
 
 Options:
-    -h, --help               Print this message
-    -o, --output-path PATH   Path the output is written to, otherwise stdout is used
-    -f, --output-format FMT  Output format [default: toml]
-                             Valid values: toml, json
-    --features FEATURES      Space-separated list of features
-    --no-default-features    Do not include the `default` feature
-    --manifest-path PATH     Path to the manifest
-    -v, --verbose            Use verbose output
-    -q, --quiet              No output printed to stdout
-    --color WHEN             Coloring: auto, always, never
+    -h, --help                 Print this message
+    -o, --output-path PATH     Path the output is written to, otherwise stdout is used
+    -f, --output-format FMT    Output format [default: toml]
+                               Valid values: toml, json
+    --features FEATURES        Space-separated list of features
+    --no-default-features      Do not include the `default` feature
+    --manifest-path PATH       Path to the manifest
+    --format-version VERSION   Format version [default: 1]
+                               Valid values: 1
+    -v, --verbose              Use verbose output
+    -q, --quiet                No output printed to stdout
+    --color WHEN               Coloring: auto, always, never
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
@@ -57,6 +60,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         no_default_features: options.flag_no_default_features,
         output_format: options.flag_output_format,
         output_to: output_to,
+        version: options.flag_format_version,
     };
 
     try!(output_metadata(options, config));
index 6d4415e519056ff229e9091dc5be5a853ccc2539..72d4ab50adc67296d8e0ef83b6d1f85ab20aeef8 100644 (file)
@@ -10,6 +10,7 @@ use toml;
 use util::config::Config;
 use util::{paths, CargoResult};
 
+const VERSION: u32 = 1;
 
 /// Where the dependencies should be written to.
 pub enum OutputTo {
@@ -19,10 +20,11 @@ pub enum OutputTo {
 
 pub struct OutputMetadataOptions<'a> {
     pub features: Vec<String>,
-    pub output_format: String,
-    pub output_to: OutputTo,
     pub manifest_path: &'a Path,
     pub no_default_features: bool,
+    pub output_format: String,
+    pub output_to: OutputTo,
+    pub version: u32,
 }
 
 /// Loads the manifest, resolves the dependencies of the project to the concrete
@@ -54,9 +56,11 @@ pub fn output_metadata(opt: OutputMetadataOptions, config: &Config) -> CargoResu
                                          opt.no_default_features));
     let (packages, resolve) = deps;
 
+    assert_eq!(opt.version, VERSION);
     let output = ExportInfo {
         packages: &packages,
         resolve: &resolve,
+        version: VERSION,
     };
 
     let serialized_str = match &opt.output_format.to_ascii_uppercase()[..] {
@@ -78,6 +82,7 @@ pub fn output_metadata(opt: OutputMetadataOptions, config: &Config) -> CargoResu
 struct ExportInfo<'a> {
     packages: &'a [Package],
     resolve: &'a Resolve,
+    version: u32,
 }
 
 
index 7ae3df66995a11affff7476583cc98664022fe62..4dc307c92c2cd57f35cbbeea17d5f3bbabb9686a 100644 (file)
@@ -14,7 +14,8 @@ test!(cargo_metadata_simple {
     let p = project("foo")
             .file("Cargo.toml", &basic_bin_manifest("foo"));
 
-    assert_that(p.cargo_process("metadata"), execs().with_stdout(r#"
+    assert_that(p.cargo_process("metadata"), execs().with_stdout(r#"version = 1
+
 [[packages]]
 dependencies = []
 id = "foo 0.5.0 [..]"
@@ -76,7 +77,8 @@ test!(cargo_metadata_simple_json {
                     "dependencies" : []
                 },
                 "metadata": null
-            }
+            },
+            "version": 1
         }"#.split_whitespace().collect::<String>()));
 });